#pragma once

#include "../_inc_arc/def_archive.h"
#include "SkinListCtrl.h"

#include "../_inc_util/UtilTime.h"
#include "../_inc/TimeList.h"
#include "SortedArray.h"
#include "ListMgr.h"

#include "../_inc/def_interface.h"

// CWndListEvent

class CWndListEvent : public CWnd
{
	DECLARE_DYNAMIC(CWndListEvent)

private:
	CSkinListCtrl		m_SkinList;
	CFont				m_ListFont;

	CUtilTime			m_UtilTime;

	CSortedArray	<CTimeList *, CTimeList *> m_arrPlayList;

	CSortedArray	<CTimeList *, CTimeList *> m_arrRecList[MAX_REC_TYPE];

	int m_nFontHeight;
	int m_nListWidth;

	BOOL m_bInitList;

	BOOL m_bChecked;
	BOOL m_bRecType[MAX_REC_TYPE];
	CListMgr *m_pListMgr;

	int m_nMode;

public:
	CWndListEvent();
	virtual ~CWndListEvent();

	void SetListMgr(CListMgr *pListMgr)	{ m_pListMgr = pListMgr; };
	void ArrangeRecList();
	void LoadRecList();
	void ResetList();

	int GetListItem(int nStartCount);
	int GetSelectedItem();


	int SearchIndex(time_t tSearchTime, BOOL bFindNearBehind);
	int binarySearchIndex(time_t tSearchTime, int nStart, int nEnd, BOOL *bFind);
	int linearSearchIndex(time_t tSearchTime, int nStart, int nEnd, BOOL *bFind);

	CTimeList *GetBackupIndex(int nIndex);


	void SetCheckAll();
	void SetUncheckAll();

	BOOL GetCheckStatus() { return m_bChecked; };
	void NotifyCheckStatus(BOOL bChecked);

	void SetSelectRecType(DWORD dwRecType, BOOL bChecked);

	int GetRecIndexNumberFromListNumber(int nListNumber);
	int GetRecIndexNumberAvailable(int nIndexNumber);
	int GetCurrentRecIndexNumber();
	CTimeList *GetRecIndex(int nIndexNumber);
	void SetRecIndex(int nIndexNumber);
	int GetRecIndexSize();

	int GetBackupIndexStart();
	int GetBackupIndexNext(int nIndex, BOOL bChecked);
	int GetBackupIndexEnd();

	void RefreshLang();


private:
	void InitListCtrl();
	void MergetList();

protected:
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
	afx_msg void OnEndtrackSkinList(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnPaint();
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg long OnPlbMessage(UINT wParam, LONG lParam);
	afx_msg long OnCtlMessage(UINT wParam, LONG lParam);
	DECLARE_MESSAGE_MAP()
public:	
	
	virtual BOOL PreTranslateMessage(MSG* pMsg);
};


